
class Helper_fileChopper(object):
    instance = None     

    def __new__(cls, *args, **kargs): 
        if cls.instance is None:
            cls.instance = object.__new__(cls, *args, **kargs)
        return cls.instance
        
    def fileChopp(self,aFile,blockSize):
        strToChop = aFile.getData()
        
        fileSize = aFile.getSize()
        partsList = []
                
        for inicio in range (0,fileSize,blockSize):
            if ((fileSize-inicio) >= blockSize):
                strBlock = aFile.getParcialData(inicio, inicio+blockSize)
            else:
                strBlock = aFile.getParcialData(inicio, inicio+(fileSize-inicio))
        
            partsList.append(strBlock)
            
        return partsList
    
    def blocksNeeded(self,aFile,blockSize):
        strToChop = aFile.getData()
        
        fileSize = aFile.getSize()
        partsNeeded = 0
                
        for inicio in range (0,fileSize,blockSize):
            if ((fileSize-inicio) >= blockSize):
                strBlock = aFile.getParcialData(inicio, inicio+blockSize)
            else:
                strBlock = aFile.getParcialData(inicio, inicio+(fileSize-inicio))
        
            partsNeeded = partsNeeded + 1
            
        return partsNeeded 
    
                
                
    def fileJoiner(self,aPartsList):
        tempStr = ""
            
        for i in range (len(aPartsList)):
            ass = aPartsList[i]
            tempStr = tempStr+ass
                
        return tempStr